﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DwarfInterpreter
{
    class DwarfToken : Token
    {
        public static string[] DWARF_SYMBOLS = { 
                                                   "right", 
                                                   "left", 
                                                   "forward", 
                                                   "backward", 
                                                   "say", 
                                                   "go", 
                                                   "stop", 
                                                   "attack", 
                                                   "work" 
                                               };

        private int tokenIndex = -1;

        public DwarfToken(string str)
        {
            for (int i = 0; i < DWARF_SYMBOLS.Length; ++i )
            {
                if (DWARF_SYMBOLS[i].CompareTo(str) == 0)
                {
                    tokenIndex = i;
                    return;
                }
            }
        }

        override public void Run(Dwarf dwarf)
        {
            switch (tokenIndex)
            {
                case 0: //"right" 
                    dwarf.MoveRight();
                    break;
                case 1: //"left"
                    dwarf.MoveLeft();
                    break;
                case 2: //"forward" 
                    dwarf.MoveForward();
                    break;
                case 3: //"backward" 
                    dwarf.MoveBackward();
                    break;
                case 4: //"say" 
                    dwarf.Say();
                    break;
                case 5: //"go" 
                    dwarf.Go();
                    break;
                case 6: //"stop" 
                    dwarf.Stop();
                    break;
                case 7: //"attack" 
                    dwarf.Attack();
                    break;
                case 8: //"work" 
                    dwarf.Work();
                    break;
            }
        }

        public static bool IsDwarfCommand(string str)
        {
            return DWARF_SYMBOLS.Contains(str);
        }
        
    }
}
